using System;
using System.Collections.Generic;
using System.Linq;
using QuickBencher;
using System.Text;

namespace SampleBenchmarks
{
    public class String_concatination : Runnable
    {
        public void Run()
        {            
            const int ITERATIONS = 60000;

            Benchmark.Bm((x) =>
            {
                x.Report("+=:", () => 
                { 
                    string s = string.Empty;
                    for (int i = 0; i < ITERATIONS; i++)
                        s += Convert.ToChar(i);
                });
                x.Report("Concat:", () =>
                {
                    string s = string.Empty;
                    for (int i = 0; i < ITERATIONS; i++)
                        s = String.Concat(s, Convert.ToChar(i));
                });
                x.Report("Builder:", () =>
                {
                    string s = string.Empty;
                    var sb = new StringBuilder();
                    for (int i = 0; i < ITERATIONS; i++)
                        sb.Append(Convert.ToChar(i));
                    s = sb.ToString();
                });
                x.Report("Format:", () =>
                {
                    string s = string.Empty;
                    for (int i = 0; i < ITERATIONS; i++)
                        s = String.Format("{0}{1}", s, Convert.ToChar(i));
                });
                x.Report("Join:", () => 
                {
                    string s = string.Empty;
                    var arr = new string[ITERATIONS];
                    for (int i = 0; i < ITERATIONS; i++)
                        arr[i] = Convert.ToChar(i).ToString();
                    s = String.Join("", arr);
                });
                
            });
        }
    }
}
